// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements.  See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership.  The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License.  You may obtain a copy of the License at
//
//   http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied.  See the License for the
// specific language governing permissions and limitations
// under the License.


suite("test_cast_to_double_from_datetimev2_0_part8") {

    // This test case is generated from the correspoinding be UT test case,
    // update this case if the correspoinding be UT test case is updated,
    // e.g.: ../run-be-ut.sh --run --filter=FunctionCastToDecimalTest.* --gen_regression_case
    sql "drop table if exists test_cast_to_double_from_datetimev2_0_part8_8_nullable;"
    sql "create table test_cast_to_double_from_datetimev2_0_part8_8_nullable(f1 int, f2 datetimev2(0)) properties('replication_num'='1');"
    sql """insert into test_cast_to_double_from_datetimev2_0_part8_8_nullable values (0, "2025-12-28 00:59:01"),(1, "2025-12-28 00:59:01"),(2, "2025-12-28 00:59:01"),(3, "2025-12-28 00:59:59"),(4, "2025-12-28 00:59:59"),(5, "2025-12-28 00:59:59"),(6, "2025-12-28 01:00:00"),(7, "2025-12-28 01:00:00"),(8, "2025-12-28 01:00:00"),(9, "2025-12-28 01:00:01"),(10, "2025-12-28 01:00:01"),(11, "2025-12-28 01:00:01"),(12, "2025-12-28 01:00:59"),(13, "2025-12-28 01:00:59"),(14, "2025-12-28 01:00:59"),(15, "2025-12-28 01:01:00"),(16, "2025-12-28 01:01:00"),(17, "2025-12-28 01:01:00"),(18, "2025-12-28 01:01:01"),(19, "2025-12-28 01:01:01"),
      (20, "2025-12-28 01:01:01"),(21, "2025-12-28 01:01:59"),(22, "2025-12-28 01:01:59"),(23, "2025-12-28 01:01:59"),(24, "2025-12-28 01:59:00"),(25, "2025-12-28 01:59:00"),(26, "2025-12-28 01:59:00"),(27, "2025-12-28 01:59:01"),(28, "2025-12-28 01:59:01"),(29, "2025-12-28 01:59:01"),(30, "2025-12-28 01:59:59"),(31, "2025-12-28 01:59:59"),(32, "2025-12-28 01:59:59"),(33, "2025-12-28 23:00:00"),(34, "2025-12-28 23:00:00"),(35, "2025-12-28 23:00:00"),(36, "2025-12-28 23:00:01"),(37, "2025-12-28 23:00:01"),(38, "2025-12-28 23:00:01"),(39, "2025-12-28 23:00:59"),
      (40, "2025-12-28 23:00:59"),(41, "2025-12-28 23:00:59"),(42, "2025-12-28 23:01:00"),(43, "2025-12-28 23:01:00"),(44, "2025-12-28 23:01:00"),(45, "2025-12-28 23:01:01"),(46, "2025-12-28 23:01:01"),(47, "2025-12-28 23:01:01"),(48, "2025-12-28 23:01:59"),(49, "2025-12-28 23:01:59"),(50, "2025-12-28 23:01:59"),(51, "2025-12-28 23:59:00"),(52, "2025-12-28 23:59:00"),(53, "2025-12-28 23:59:00"),(54, "2025-12-28 23:59:01"),(55, "2025-12-28 23:59:01"),(56, "2025-12-28 23:59:01"),(57, "2025-12-28 23:59:59"),(58, "2025-12-28 23:59:59"),(59, "2025-12-28 23:59:59"),
      (60, "9999-01-01 00:00:00"),(61, "9999-01-01 00:00:00"),(62, "9999-01-01 00:00:00"),(63, "9999-01-01 00:00:01"),(64, "9999-01-01 00:00:01"),(65, "9999-01-01 00:00:01"),(66, "9999-01-01 00:00:59"),(67, "9999-01-01 00:00:59"),(68, "9999-01-01 00:00:59"),(69, "9999-01-01 00:01:00"),(70, "9999-01-01 00:01:00"),(71, "9999-01-01 00:01:00"),(72, "9999-01-01 00:01:01"),(73, "9999-01-01 00:01:01"),(74, "9999-01-01 00:01:01"),(75, "9999-01-01 00:01:59"),(76, "9999-01-01 00:01:59"),(77, "9999-01-01 00:01:59"),(78, "9999-01-01 00:59:00"),(79, "9999-01-01 00:59:00"),
      (80, "9999-01-01 00:59:00"),(81, "9999-01-01 00:59:01"),(82, "9999-01-01 00:59:01"),(83, "9999-01-01 00:59:01"),(84, "9999-01-01 00:59:59"),(85, "9999-01-01 00:59:59"),(86, "9999-01-01 00:59:59"),(87, "9999-01-01 01:00:00"),(88, "9999-01-01 01:00:00"),(89, "9999-01-01 01:00:00"),(90, "9999-01-01 01:00:01"),(91, "9999-01-01 01:00:01"),(92, "9999-01-01 01:00:01"),(93, "9999-01-01 01:00:59"),(94, "9999-01-01 01:00:59"),(95, "9999-01-01 01:00:59"),(96, "9999-01-01 01:01:00"),(97, "9999-01-01 01:01:00"),(98, "9999-01-01 01:01:00"),(99, "9999-01-01 01:01:01"),
      (100, "9999-01-01 01:01:01"),(101, "9999-01-01 01:01:01"),(102, "9999-01-01 01:01:59"),(103, "9999-01-01 01:01:59"),(104, "9999-01-01 01:01:59"),(105, "9999-01-01 01:59:00"),(106, "9999-01-01 01:59:00"),(107, "9999-01-01 01:59:00"),(108, "9999-01-01 01:59:01"),(109, "9999-01-01 01:59:01"),(110, "9999-01-01 01:59:01"),(111, "9999-01-01 01:59:59"),(112, "9999-01-01 01:59:59"),(113, "9999-01-01 01:59:59"),(114, "9999-01-01 23:00:00"),(115, "9999-01-01 23:00:00"),(116, "9999-01-01 23:00:00"),(117, "9999-01-01 23:00:01"),(118, "9999-01-01 23:00:01"),(119, "9999-01-01 23:00:01"),
      (120, "9999-01-01 23:00:59"),(121, "9999-01-01 23:00:59"),(122, "9999-01-01 23:00:59"),(123, "9999-01-01 23:01:00"),(124, "9999-01-01 23:01:00"),(125, "9999-01-01 23:01:00"),(126, "9999-01-01 23:01:01"),(127, "9999-01-01 23:01:01"),(128, "9999-01-01 23:01:01"),(129, "9999-01-01 23:01:59"),(130, "9999-01-01 23:01:59"),(131, "9999-01-01 23:01:59"),(132, "9999-01-01 23:59:00"),(133, "9999-01-01 23:59:00"),(134, "9999-01-01 23:59:00"),(135, "9999-01-01 23:59:01"),(136, "9999-01-01 23:59:01"),(137, "9999-01-01 23:59:01"),(138, "9999-01-01 23:59:59"),(139, "9999-01-01 23:59:59"),
      (140, "9999-01-01 23:59:59"),(141, "9999-01-28 00:00:00"),(142, "9999-01-28 00:00:00"),(143, "9999-01-28 00:00:00"),(144, "9999-01-28 00:00:01"),(145, "9999-01-28 00:00:01"),(146, "9999-01-28 00:00:01"),(147, "9999-01-28 00:00:59"),(148, "9999-01-28 00:00:59"),(149, "9999-01-28 00:00:59"),(150, "9999-01-28 00:01:00"),(151, "9999-01-28 00:01:00"),(152, "9999-01-28 00:01:00"),(153, "9999-01-28 00:01:01"),(154, "9999-01-28 00:01:01"),(155, "9999-01-28 00:01:01"),(156, "9999-01-28 00:01:59"),(157, "9999-01-28 00:01:59"),(158, "9999-01-28 00:01:59"),(159, "9999-01-28 00:59:00"),
      (160, "9999-01-28 00:59:00"),(161, "9999-01-28 00:59:00"),(162, "9999-01-28 00:59:01"),(163, "9999-01-28 00:59:01"),(164, "9999-01-28 00:59:01"),(165, "9999-01-28 00:59:59"),(166, "9999-01-28 00:59:59"),(167, "9999-01-28 00:59:59"),(168, "9999-01-28 01:00:00"),(169, "9999-01-28 01:00:00"),(170, "9999-01-28 01:00:00"),(171, "9999-01-28 01:00:01"),(172, "9999-01-28 01:00:01"),(173, "9999-01-28 01:00:01"),(174, "9999-01-28 01:00:59"),(175, "9999-01-28 01:00:59"),(176, "9999-01-28 01:00:59"),(177, "9999-01-28 01:01:00"),(178, "9999-01-28 01:01:00"),(179, "9999-01-28 01:01:00"),
      (180, "9999-01-28 01:01:01"),(181, "9999-01-28 01:01:01"),(182, "9999-01-28 01:01:01"),(183, "9999-01-28 01:01:59"),(184, "9999-01-28 01:01:59"),(185, "9999-01-28 01:01:59"),(186, "9999-01-28 01:59:00"),(187, "9999-01-28 01:59:00"),(188, "9999-01-28 01:59:00"),(189, "9999-01-28 01:59:01"),(190, "9999-01-28 01:59:01"),(191, "9999-01-28 01:59:01"),(192, "9999-01-28 01:59:59"),(193, "9999-01-28 01:59:59"),(194, "9999-01-28 01:59:59")
      ,(195, null);
    """

    sql "set enable_strict_cast=true;"

    test {
        sql """select f1, cast(f2 as double) from test_cast_to_double_from_datetimev2_0_part8_8_nullable order by 1;"""
        exception ""
    }
    sql "set enable_strict_cast=false;"
    qt_sql_8_non_strict 'select f1, cast(f2 as double) from test_cast_to_double_from_datetimev2_0_part8_8_nullable order by 1;'

    sql "drop table if exists test_cast_to_double_from_datetimev2_0_part8_8_not_nullable;"
    sql "create table test_cast_to_double_from_datetimev2_0_part8_8_not_nullable(f1 int, f2 datetimev2(0)) properties('replication_num'='1');"
    sql """insert into test_cast_to_double_from_datetimev2_0_part8_8_not_nullable values (0, "2025-12-28 00:59:01"),(1, "2025-12-28 00:59:01"),(2, "2025-12-28 00:59:01"),(3, "2025-12-28 00:59:59"),(4, "2025-12-28 00:59:59"),(5, "2025-12-28 00:59:59"),(6, "2025-12-28 01:00:00"),(7, "2025-12-28 01:00:00"),(8, "2025-12-28 01:00:00"),(9, "2025-12-28 01:00:01"),(10, "2025-12-28 01:00:01"),(11, "2025-12-28 01:00:01"),(12, "2025-12-28 01:00:59"),(13, "2025-12-28 01:00:59"),(14, "2025-12-28 01:00:59"),(15, "2025-12-28 01:01:00"),(16, "2025-12-28 01:01:00"),(17, "2025-12-28 01:01:00"),(18, "2025-12-28 01:01:01"),(19, "2025-12-28 01:01:01"),
      (20, "2025-12-28 01:01:01"),(21, "2025-12-28 01:01:59"),(22, "2025-12-28 01:01:59"),(23, "2025-12-28 01:01:59"),(24, "2025-12-28 01:59:00"),(25, "2025-12-28 01:59:00"),(26, "2025-12-28 01:59:00"),(27, "2025-12-28 01:59:01"),(28, "2025-12-28 01:59:01"),(29, "2025-12-28 01:59:01"),(30, "2025-12-28 01:59:59"),(31, "2025-12-28 01:59:59"),(32, "2025-12-28 01:59:59"),(33, "2025-12-28 23:00:00"),(34, "2025-12-28 23:00:00"),(35, "2025-12-28 23:00:00"),(36, "2025-12-28 23:00:01"),(37, "2025-12-28 23:00:01"),(38, "2025-12-28 23:00:01"),(39, "2025-12-28 23:00:59"),
      (40, "2025-12-28 23:00:59"),(41, "2025-12-28 23:00:59"),(42, "2025-12-28 23:01:00"),(43, "2025-12-28 23:01:00"),(44, "2025-12-28 23:01:00"),(45, "2025-12-28 23:01:01"),(46, "2025-12-28 23:01:01"),(47, "2025-12-28 23:01:01"),(48, "2025-12-28 23:01:59"),(49, "2025-12-28 23:01:59"),(50, "2025-12-28 23:01:59"),(51, "2025-12-28 23:59:00"),(52, "2025-12-28 23:59:00"),(53, "2025-12-28 23:59:00"),(54, "2025-12-28 23:59:01"),(55, "2025-12-28 23:59:01"),(56, "2025-12-28 23:59:01"),(57, "2025-12-28 23:59:59"),(58, "2025-12-28 23:59:59"),(59, "2025-12-28 23:59:59"),
      (60, "9999-01-01 00:00:00"),(61, "9999-01-01 00:00:00"),(62, "9999-01-01 00:00:00"),(63, "9999-01-01 00:00:01"),(64, "9999-01-01 00:00:01"),(65, "9999-01-01 00:00:01"),(66, "9999-01-01 00:00:59"),(67, "9999-01-01 00:00:59"),(68, "9999-01-01 00:00:59"),(69, "9999-01-01 00:01:00"),(70, "9999-01-01 00:01:00"),(71, "9999-01-01 00:01:00"),(72, "9999-01-01 00:01:01"),(73, "9999-01-01 00:01:01"),(74, "9999-01-01 00:01:01"),(75, "9999-01-01 00:01:59"),(76, "9999-01-01 00:01:59"),(77, "9999-01-01 00:01:59"),(78, "9999-01-01 00:59:00"),(79, "9999-01-01 00:59:00"),
      (80, "9999-01-01 00:59:00"),(81, "9999-01-01 00:59:01"),(82, "9999-01-01 00:59:01"),(83, "9999-01-01 00:59:01"),(84, "9999-01-01 00:59:59"),(85, "9999-01-01 00:59:59"),(86, "9999-01-01 00:59:59"),(87, "9999-01-01 01:00:00"),(88, "9999-01-01 01:00:00"),(89, "9999-01-01 01:00:00"),(90, "9999-01-01 01:00:01"),(91, "9999-01-01 01:00:01"),(92, "9999-01-01 01:00:01"),(93, "9999-01-01 01:00:59"),(94, "9999-01-01 01:00:59"),(95, "9999-01-01 01:00:59"),(96, "9999-01-01 01:01:00"),(97, "9999-01-01 01:01:00"),(98, "9999-01-01 01:01:00"),(99, "9999-01-01 01:01:01"),
      (100, "9999-01-01 01:01:01"),(101, "9999-01-01 01:01:01"),(102, "9999-01-01 01:01:59"),(103, "9999-01-01 01:01:59"),(104, "9999-01-01 01:01:59"),(105, "9999-01-01 01:59:00"),(106, "9999-01-01 01:59:00"),(107, "9999-01-01 01:59:00"),(108, "9999-01-01 01:59:01"),(109, "9999-01-01 01:59:01"),(110, "9999-01-01 01:59:01"),(111, "9999-01-01 01:59:59"),(112, "9999-01-01 01:59:59"),(113, "9999-01-01 01:59:59"),(114, "9999-01-01 23:00:00"),(115, "9999-01-01 23:00:00"),(116, "9999-01-01 23:00:00"),(117, "9999-01-01 23:00:01"),(118, "9999-01-01 23:00:01"),(119, "9999-01-01 23:00:01"),
      (120, "9999-01-01 23:00:59"),(121, "9999-01-01 23:00:59"),(122, "9999-01-01 23:00:59"),(123, "9999-01-01 23:01:00"),(124, "9999-01-01 23:01:00"),(125, "9999-01-01 23:01:00"),(126, "9999-01-01 23:01:01"),(127, "9999-01-01 23:01:01"),(128, "9999-01-01 23:01:01"),(129, "9999-01-01 23:01:59"),(130, "9999-01-01 23:01:59"),(131, "9999-01-01 23:01:59"),(132, "9999-01-01 23:59:00"),(133, "9999-01-01 23:59:00"),(134, "9999-01-01 23:59:00"),(135, "9999-01-01 23:59:01"),(136, "9999-01-01 23:59:01"),(137, "9999-01-01 23:59:01"),(138, "9999-01-01 23:59:59"),(139, "9999-01-01 23:59:59"),
      (140, "9999-01-01 23:59:59"),(141, "9999-01-28 00:00:00"),(142, "9999-01-28 00:00:00"),(143, "9999-01-28 00:00:00"),(144, "9999-01-28 00:00:01"),(145, "9999-01-28 00:00:01"),(146, "9999-01-28 00:00:01"),(147, "9999-01-28 00:00:59"),(148, "9999-01-28 00:00:59"),(149, "9999-01-28 00:00:59"),(150, "9999-01-28 00:01:00"),(151, "9999-01-28 00:01:00"),(152, "9999-01-28 00:01:00"),(153, "9999-01-28 00:01:01"),(154, "9999-01-28 00:01:01"),(155, "9999-01-28 00:01:01"),(156, "9999-01-28 00:01:59"),(157, "9999-01-28 00:01:59"),(158, "9999-01-28 00:01:59"),(159, "9999-01-28 00:59:00"),
      (160, "9999-01-28 00:59:00"),(161, "9999-01-28 00:59:00"),(162, "9999-01-28 00:59:01"),(163, "9999-01-28 00:59:01"),(164, "9999-01-28 00:59:01"),(165, "9999-01-28 00:59:59"),(166, "9999-01-28 00:59:59"),(167, "9999-01-28 00:59:59"),(168, "9999-01-28 01:00:00"),(169, "9999-01-28 01:00:00"),(170, "9999-01-28 01:00:00"),(171, "9999-01-28 01:00:01"),(172, "9999-01-28 01:00:01"),(173, "9999-01-28 01:00:01"),(174, "9999-01-28 01:00:59"),(175, "9999-01-28 01:00:59"),(176, "9999-01-28 01:00:59"),(177, "9999-01-28 01:01:00"),(178, "9999-01-28 01:01:00"),(179, "9999-01-28 01:01:00"),
      (180, "9999-01-28 01:01:01"),(181, "9999-01-28 01:01:01"),(182, "9999-01-28 01:01:01"),(183, "9999-01-28 01:01:59"),(184, "9999-01-28 01:01:59"),(185, "9999-01-28 01:01:59"),(186, "9999-01-28 01:59:00"),(187, "9999-01-28 01:59:00"),(188, "9999-01-28 01:59:00"),(189, "9999-01-28 01:59:01"),(190, "9999-01-28 01:59:01"),(191, "9999-01-28 01:59:01"),(192, "9999-01-28 01:59:59"),(193, "9999-01-28 01:59:59"),(194, "9999-01-28 01:59:59");
    """

    sql "set enable_strict_cast=true;"

    test {
        sql """select f1, cast(f2 as double) from test_cast_to_double_from_datetimev2_0_part8_8_not_nullable order by 1;"""
        exception ""
    }
    sql "set enable_strict_cast=false;"
    qt_sql_8_non_strict 'select f1, cast(f2 as double) from test_cast_to_double_from_datetimev2_0_part8_8_not_nullable order by 1;'

}